// pages/volunteer/points.js
Page({
  data: {
    userInfo: {
      currentPoints: 109346,
      totalPoints: 109346,
      redeemedPoints: 200
    },
    transactions: [
      {
        month: '2026年9月',
        expenditure: 66,
        income: 88,
        transactions: [
          {
            id: 1,
            title: '参加志愿活动',
            date: '12-21',
            amount: 88,
            type: 'income'
          },
          {
            id: 2,
            title: '兑换商品',
            date: '12-21',
            amount: 22,
            type: 'expense'
          }
        ]
      },
      {
        month: '2026年8月',
        expenditure: 45,
        income: 120,
        transactions: [
          {
            id: 3,
            title: '每日登录',
            date: '08-15',
            amount: 5,
            type: 'income'
          },
          {
            id: 4,
            title: '发布推文',
            date: '08-10',
            amount: 30,
            type: 'income'
          },
          {
            id: 5,
            title: '兑换商品',
            date: '08-05',
            amount: 45,
            type: 'expense'
          }
        ]
      },
      {
        month: '2026年7月',
        expenditure: 100,
        income: 200,
        transactions: [
          {
            id: 6,
            title: '参与活动，上传现场照片',
            date: '07-20',
            amount: 50,
            type: 'income'
          },
          {
            id: 7,
            title: '推荐志愿者',
            date: '07-15',
            amount: 100,
            type: 'income'
          },
          {
            id: 8,
            title: '兑换商品',
            date: '07-10',
            amount: 100,
            type: 'expense'
          }
        ]
      }
    ]
  },

  onLoad: function (options) {
    console.log('积分明细页面加载');
    this.loadUserData();
  },

  onShow: function () {
    // 页面显示时刷新数据
    this.refreshData();
  },

  // 加载用户数据
  loadUserData: function () {
    // 从本地存储或服务器获取用户数据
    const userData = wx.getStorageSync('volunteerUserData');
    if (userData) {
      this.setData({
        userInfo: { ...this.data.userInfo, ...userData }
      });
    }
  },

  // 刷新数据
  refreshData: function () {
    // 刷新积分和交易记录
    this.loadUserData();
  },



  // 分享功能
  onShareAppMessage: function () {
    return {
      title: '我的积分明细',
      path: '/pages/volunteer/points',
      imageUrl: '/images/share-points.png'
    };
  },

  // 分享到朋友圈
  onShareTimeline: function () {
    return {
      title: '我的积分明细',
      imageUrl: '/images/share-points.png'
    };
  },

  // 下拉刷新
  onPullDownRefresh: function () {
    this.refreshData();
    setTimeout(() => {
      wx.stopPullDownRefresh();
    }, 1000);
  }
});